package practice;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lenovo
 * Date: 2022-09-06
 * Time: 9:36
 */
public class P2 {
    public static void main(String[] args) throws InterruptedException {
        //创建一个线程数组
      Thread[] threads = new Thread[20];
        for (int i = 0; i < 20; i++) {
            final int n = i;
            //给每个线程重写run
            threads[i] = new Thread(()->{}){
                @Override
                public void run() {
                    System.out.println(n);//内部类使用外部类局部变量必须是final修饰
                }
            };
        }
        //给每个线程调用start
        for (Thread t: threads) {
            t.start();
        }
        //main线程阻塞
        for (Thread t: threads) {
            t.join();
        }
        System.out.println("ok");


    }
}
